﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Collections;

namespace Licenta1.Shapes
{
    [Serializable]
    class Circle : Shape
    {
        Expression parameters;
        public double radius;
        public Point O;
        bool init = false;

        public Circle(Context con, Expression param)
            : base(con)
        {
            parameters = param;

        }

        public Circle(Context con, Point p, double e)
            : base(con)
        {
            O = p;
            radius = e;
            init = true;
        }

        private void CheckParameters()
        {
            try
            {
                ParameterList p_list = (ParameterList)parameters;

                O = (Point)p_list.FirstValue;
                radius = (double)p_list.SecondValue;

            }
            catch (Exception e)
            {
                Console.WriteLine("Ex: " + e);
            }
            init = false;

        }



        public override string Display()
        {
            if (!init)
                CheckParameters();
            init = true;

            return "{C " + O.Display() + " r: " + radius + " }";
        }

        public override object Value
        {
            get
            {
                if (!init)
                    CheckParameters();
                return this;
            }
        }

        public override void Draw()
        {
            if (!init)
                CheckParameters();

            //context.mp.objectsList.Add(this.GetClone());
            context.mp.objectsList.Add(new TinyRaytracer.MainParsing.ObjectToDraw("circle", (Shape)this.GetClone(), context.activeColor, context.activePen));
        }

        public override object GetClone()
        {
            return new Circle(context, (Point)O.GetClone(), radius);
        }
    }
}